package org.csu.molediary.api.controller.front;

import org.csu.molediary.api.common.CommonResponse;
import org.csu.molediary.api.entity.Tag;
import org.csu.molediary.api.service.TagService;
import org.csu.molediary.api.vo.DiaryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/tags/")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping("allTags")
    @ResponseBody
    //获得所有话题
    public CommonResponse<List<Tag>> getAllTags(){
        return tagService.getAllTags();
    }

    @GetMapping("tagList/{tagid}")
    @ResponseBody
    //获得某话题下所有日记
    public CommonResponse<List<DiaryVO>> getDiaryByTagid(@PathVariable int tagid){
        return tagService.getDiaryByTagid(tagid);
    }

    @GetMapping("onetag/{tagcontent}")
    @ResponseBody
    //通过tagcontent获取tag
    public CommonResponse<Tag> getOneTagByTagcontent(@PathVariable String  tagcontent){
        return tagService.getTagByTagContent(tagcontent);
    }

}
